package com.og.managedbean;

import java.io.Serializable;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.enterprise.context.ApplicationScoped;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named;

import com.og.backingbean.*;
import com.og.dao.CRUDEntityDAO;

/**
 * @author Renaud DIANA
 *
 */
@Named
@ApplicationScoped
public class ListBean implements Serializable {

	private static final long serialVersionUID = 1L;

	private List<Application> listApplication;
	private List<ApplicationHistory> listApplicationHistory;
	private List<Bug> listBug;
	private List<Company> listCompany;
	private List<Composition> listComposition;
	private List<Contract> listContract;
	private List<Module> listModule;
	private List<ModuleHistory> listModuleHistory;
	private List<Person> listPerson;
	private List<Solution> listSolution;
	private List<Status> listStatus;
	private List<Ticket> listTicket;
	private List<TimeSheet> listTimeSheet;
	private List<TimeSheetDate> listTimeSheetDate;
	private List<Type> listType;
	
	/* Dependency injection */
	// Model
    @Inject
    CRUDEntityDAO<Application> applicationDAO;
    @Inject
    CRUDEntityDAO<ApplicationHistory> applicationHistoryDAO;    
    @Inject
    CRUDEntityDAO<Bug> bugDAO;
    @Inject
    CRUDEntityDAO<Company> companyDAO;
    @Inject
    CRUDEntityDAO<Composition> compositionDAO;
    @Inject
    CRUDEntityDAO<Contract> contractDAO;
    @Inject
    CRUDEntityDAO<Module> moduleDAO;
    @Inject
    CRUDEntityDAO<ModuleHistory> moduleHistoryDAO;
    @Inject
    CRUDEntityDAO<Person> personDAO;
    @Inject
    CRUDEntityDAO<Solution> solutionDAO;
    @Inject
    CRUDEntityDAO<Status> statusDAO;
    @Inject
    CRUDEntityDAO<Ticket> ticketDAO;
    @Inject
    CRUDEntityDAO<TimeSheet> timeSheetDAO;
    @Inject
    CRUDEntityDAO<TimeSheetDate> timeSheetDateDAO;
    @Inject
    CRUDEntityDAO<Type> typeDAO;
    
    // BackingBean
    @Inject
    Application application;    
    @Inject
    ApplicationHistory applicationHistory;
    @Inject
    Bug bug;
    @Inject
    Company company;    
    @Inject
    Composition composition;
    @Inject
    Contract contract;
    @Inject
    Module module;    
    @Inject
    ModuleHistory moduleHistory;
    @Inject
    Person person;
    @Inject
    Solution solution;    
    @Inject
    Status status;
    @Inject
    Ticket ticket;
    @Inject
    TimeSheet timeSheet;    
    @Inject
    TimeSheetDate timeSheetDate;
    @Inject
    Type type;
    
    /* -------------------- */
	
	/**
	 * Default constructor
	 */
	public ListBean() {
		// TODO Auto-generated constructor stub
	}
	
	@PostConstruct
	public void generateLists() {
		
		findAllApplication();
		//findAllApplicationHistory();
		//findAllBug();
		findAllCompany();
		findAllComposition();
		findAllContract();
		findAllModule();
		//findAllModuleHistory();		
		findAllPerson();
		//findAllSolution();
		findAllStatus();
		//findAllTicket();
		findAllTimeSheet();
		findAllTimeSheetDate();
		findAllType();
	}
	
	public String findAllApplication() {
		
		// Call model			
		listApplication = applicationDAO.findByNamedQuery("Application.findAll", application, null);
		
		// Add message
		FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("listApplication Successful"));  
		
		// Navigation case
		return "";
		//return "success";
	}
	
	public String findAllApplicationHistory() {
		
		// Call model			
		listApplicationHistory = applicationHistoryDAO.findByNamedQuery("ApplicationHistory.findAll", applicationHistory, null);
		
		// Add message
		FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("listApplicationHistory Successful"));  
		
		// Navigation case
		return "";
		//return "success";
	}
	
	public String findAllBug() {
	
		// Call model			
		listBug = bugDAO.findByNamedQuery("Bug.findAll", bug, null);
		
		// Add message
		FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("listBug Successful"));  
		
		// Navigation case
		return "";
		//return "success";
	}

	public String findAllCompany() {
	
		// Call model			
		listCompany = companyDAO.findByNamedQuery("Company.findAll", company, null);
		
		// Add message
		FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("listCompany Successful"));  
		
		// Navigation case
		return "";
		//return "success";
	}

	public String findAllComposition() {
	
		// Call model			
		listComposition = compositionDAO.findByNamedQuery("Composition.findAll", composition, null);
		
		// Add message
		FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("listComposition Successful"));  
		
		// Navigation case
		return "";
		//return "success";
	}

	public String findAllContract() {
	
		// Call model			
		listContract = contractDAO.findByNamedQuery("Contract.findAll", contract, null);
		
		// Add message
		FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("listContract Successful"));  
		
		// Navigation case
		return "";
		//return "success";
	}

	public String findAllModule() {
	
		// Call model			
		listModule = moduleDAO.findByNamedQuery("Module.findAll", module, null);
		
		// Add message
		FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("listModule Successful"));  
		
		// Navigation case
		return "";
		//return "success";
	}

	public String findAllModuleHistory() {
	
		// Call model			
		listModuleHistory = moduleHistoryDAO.findByNamedQuery("ModuleHistory.findAll", moduleHistory, null);
		
		// Add message
		FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("listModuleHistory Successful"));  
		
		// Navigation case
		return "";
		//return "success";
	}

	public String findAllPerson() {
	
		// Call model			
		listPerson = personDAO.findByNamedQuery("Person.findAll", person, null);
		
		// Add message
		FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("listPerson Successful"));  
		
		// Navigation case
		return "";
		//return "success";
	}

	public String findAllSolution() {
	
		// Call model			
		listSolution = solutionDAO.findByNamedQuery("Solution.findAll", solution, null);
		
		// Add message
		FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("listSolution Successful"));  
		
		// Navigation case
		return "";
		//return "success";
	}

	public String findAllStatus() {
	
		// Call model			
		listStatus = statusDAO.findByNamedQuery("Status.findAll", status, null);
		
		// Add message
		FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("listStatus Successful"));  
		
		// Navigation case
		return "";
		//return "success";
	}

	public String findAllTicket() {
	
		// Call model			
		listTicket = ticketDAO.findByNamedQuery("Ticket.findAll", ticket, null);
		
		// Add message
		FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("listTicket Successful"));  
		
		// Navigation case
		return "";
		//return "success";
	}

	public String findAllTimeSheet() {
	
		// Call model			
		listTimeSheet = timeSheetDAO.findByNamedQuery("TimeSheet.findAll", timeSheet, null);
		
		// Add message
		FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("listTimeSheet Successful"));  
		
		// Navigation case
		return "";
		//return "success";
	}

	public String findAllTimeSheetDate() {
	
		// Call model			
		listTimeSheetDate = timeSheetDateDAO.findByNamedQuery("TimeSheetDate.findAll", timeSheetDate, null);
		
		// Add message
		FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("listTimeSheetDate Successful"));  
		
		// Navigation case
		return "";
		//return "success";
	}

	public String findAllType() {
	
		// Call model			
		listType = typeDAO.findByNamedQuery("Type.findAll", type, null);
		
		// Add message
		FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("listType Successful"));  
		
		// Navigation case
		return "";
		//return "success";
	}

	// Getters and Setters
	
	public List<Application> getListApplication() {
		return listApplication;
	}

	public void setListApplication(List<Application> listApplication) {
		this.listApplication = listApplication;
	}

	public List<ApplicationHistory> getListApplicationHistory() {
		return listApplicationHistory;
	}

	public void setListApplicationHistory(List<ApplicationHistory> listApplicationHistory) {
		this.listApplicationHistory = listApplicationHistory;
	}

	public List<Bug> getListBug() {
		return listBug;
	}

	public void setListBug(List<Bug> listBug) {
		this.listBug = listBug;
	}

	public List<Company> getListCompany() {
		return listCompany;
	}

	public void setListCompany(List<Company> listCompany) {
		this.listCompany = listCompany;
	}

	public List<Composition> getListComposition() {
		return listComposition;
	}

	public void setListComposition(List<Composition> listComposition) {
		this.listComposition = listComposition;
	}

	public List<Contract> getListContract() {
		return listContract;
	}

	public void setListContract(List<Contract> listContract) {
		this.listContract = listContract;
	}

	public List<Module> getListModule() {
		return listModule;
	}

	public void setListModule(List<Module> listModule) {
		this.listModule = listModule;
	}

	public List<ModuleHistory> getListModuleHistory() {
		return listModuleHistory;
	}

	public void setListModuleHistory(List<ModuleHistory> listModuleHistory) {
		this.listModuleHistory = listModuleHistory;
	}

	public List<Person> getListPerson() {
		return listPerson;
	}

	public void setListPerson(List<Person> listPerson) {
		this.listPerson = listPerson;
	}

	public List<Solution> getListSolution() {
		return listSolution;
	}

	public void setListSolution(List<Solution> listSolution) {
		this.listSolution = listSolution;
	}

	public List<Status> getListStatus() {
		return listStatus;
	}

	public void setListStatus(List<Status> listStatus) {
		this.listStatus = listStatus;
	}

	public List<Ticket> getListTicket() {
		return listTicket;
	}

	public void setListTicket(List<Ticket> listTicket) {
		this.listTicket = listTicket;
	}

	public List<TimeSheet> getListTimeSheet() {
		return listTimeSheet;
	}

	public void setListTimeSheet(List<TimeSheet> listTimeSheet) {
		this.listTimeSheet = listTimeSheet;
	}

	public List<TimeSheetDate> getListTimeSheetDate() {
		return listTimeSheetDate;
	}

	public void setListTimeSheetDate(List<TimeSheetDate> listTimeSheetDate) {
		this.listTimeSheetDate = listTimeSheetDate;
	}

	public List<Type> getListType() {
		return listType;
	}

	public void setListType(List<Type> listType) {
		this.listType = listType;
	}

}
